/*
T-SQL (Transact-SQL, MSSQL) grammar.
The MIT License (MIT).
Copyright (c) 2017, Mark Adams (madams51703@gmail.com)
Copyright (c) 2015-2017, Ivan Kochurkin (kvanttt@gmail.com), Positive Technologies.
Copyright (c) 2016, Scott Ure (scott@redstormsoftware.com).
Copyright (c) 2016, Rui Zhang (ruizhang.ccs@gmail.com).
Copyright (c) 2016, Marcus Henriksson (kuseman80@gmail.com).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

lexer grammar TSqlLexer;

// Basic keywords (from https://msdn.microsoft.com/en-us/library/ms189822.aspx)

ADD:                                   'ADD';
ALL:                                   'ALL';
ALTER:                                 'ALTER';
AND:                                   'AND';
ANY:                                   'ANY';
AS:                                    'AS';
ASC:                                   'ASC';
AUTHORIZATION:                         'AUTHORIZATION';
BACKSLASH:                             '\\';
BACKUP:                                'BACKUP';
BEGIN:                                 'BEGIN';
BETWEEN:                               'BETWEEN';
BREAK:                                 'BREAK';
BROWSE:                                'BROWSE';
BULK:                                  'BULK';
BY:                                    'BY';
CASCADE:                               'CASCADE';
CASE:                                  'CASE';
CHECK:                                 'CHECK';
CHECKPOINT:                            'CHECKPOINT';
CLOSE:                                 'CLOSE';
CLUSTERED:                             'CLUSTERED';
COALESCE:                              'COALESCE';
COLLATE:                               'COLLATE';
COLUMN:                                'COLUMN';
COMMIT:                                'COMMIT';
COMPUTE:                               'COMPUTE';
CONSTRAINT:                            'CONSTRAINT';
CONTAINS:                              'CONTAINS';
CONTAINSTABLE:                         'CONTAINSTABLE';
CONTINUE:                              'CONTINUE';
CONVERT:                               'TRY_'? 'CONVERT';
CREATE:                                'CREATE';
CROSS:                                 'CROSS';
CURRENT:                               'CURRENT';
CURRENT_DATE:                          'CURRENT_DATE';
CURRENT_TIME:                          'CURRENT_TIME';
CURRENT_TIMESTAMP:                     'CURRENT_TIMESTAMP';
CURRENT_USER:                          'CURRENT_USER';
CURSOR:                                'CURSOR';
DATABASE:                              'DATABASE';
DBCC:                                  'DBCC';
DEALLOCATE:                            'DEALLOCATE';
DECLARE:                               'DECLARE';
DEFAULT:                               'DEFAULT';
DELETE:                                'DELETE';
DENY:                                  'DENY';
DESC:                                  'DESC';
DISK:                                  'DISK';
DISTINCT:                              'DISTINCT';
DISTRIBUTED:                           'DISTRIBUTED';
DOUBLE:                                'DOUBLE';
DOUBLE_BACK_SLASH:                     '\\\\';
DOUBLE_FORWARD_SLASH:                  '//';
DROP:                                  'DROP';
DUMP:                                  'DUMP';
ELSE:                                  'ELSE';
END:                                   'END';
ERRLVL:                                'ERRLVL';
ESCAPE:                                'ESCAPE';
EXCEPT:                                'EXCEPT';
EXECUTE:                               'EXEC' 'UTE'?;
EXISTS:                                'EXISTS';
EXIT:                                  'EXIT';
EXTERNAL:                              'EXTERNAL';
FETCH:                                 'FETCH';
FILE:                                  'FILE';
FILLFACTOR:                            'FILLFACTOR';
FOR:                                   'FOR';
FOREIGN:                               'FOREIGN';
FREETEXT:                              'FREETEXT';
FREETEXTTABLE:                         'FREETEXTTABLE';
FROM:                                  'FROM';
FULL:                                  'FULL';
FUNCTION:                              'FUNCTION';
GOTO:                                  'GOTO';
GRANT:                                 'GRANT';
GROUP:                                 'GROUP';
HAVING:                                'HAVING';
HOLDLOCK:                              'HOLDLOCK';
IDENTITY:                              'IDENTITY';
IDENTITY_INSERT:                       'IDENTITY_INSERT';
IDENTITYCOL:                           'IDENTITYCOL';
IF:                                    'IF';
IN:                                    'IN';
INDEX:                                 'INDEX';
INNER:                                 'INNER';
INSERT:                                'INSERT';
INTERSECT:                             'INTERSECT';
INTO:                                  'INTO';
IS:                                    'IS';
JOIN:                                  'JOIN';
KEY:                                   'KEY';
KILL:                                  'KILL';
LEFT:                                  'LEFT';
LIKE:                                  'LIKE';
LINENO:                                'LINENO';
LOAD:                                  'LOAD';
MERGE:                                 'MERGE';
NATIONAL:                              'NATIONAL';
NEGOTIATE:                             'NEGOTIATE';
NOCHECK:                               'NOCHECK';
NONCLUSTERED:                          'NONCLUSTERED';
NOT:                                   'NOT';
NULL_:                                 'NULL';
NULLIF:                                'NULLIF';
OF:                                    'OF';
OFF:                                   'OFF';
OFFSETS:                               'OFFSETS';
ON:                                    'ON';
OPEN:                                  'OPEN';
OPENDATASOURCE:                        'OPENDATASOURCE';
OPENQUERY:                             'OPENQUERY';
OPENROWSET:                            'OPENROWSET';
OPENJSON:                              'OPENJSON';
OPENXML:                               'OPENXML';
OPTION:                                'OPTION';
OR:                                    'OR';
ORDER:                                 'ORDER';
OUTER:                                 'OUTER';
OVER:                                  'OVER';
PERCENT:                               'PERCENT';
PIVOT:                                 'PIVOT';
PLAN:                                  'PLAN';
PRECISION:                             'PRECISION';
PRIMARY:                               'PRIMARY';
PRINT:                                 'PRINT';
PROC:                                  'PROC';
PROCEDURE:                             'PROCEDURE';
PUBLIC:                                'PUBLIC';
RAISERROR:                             'RAISERROR';
RAW:                                   'RAW';
READ:                                  'READ';
READTEXT:                              'READTEXT';
RECONFIGURE:                           'RECONFIGURE';
REFERENCES:                            'REFERENCES';
REPLICATION:                           'REPLICATION';
RESTORE:                               'RESTORE';
RESTRICT:                              'RESTRICT';
RETURN:                                'RETURN';
REVERT:                                'REVERT';
REVOKE:                                'REVOKE';
RIGHT:                                 'RIGHT';
ROLLBACK:                              'ROLLBACK';
ROWCOUNT:                              'ROWCOUNT';
ROWGUIDCOL:                            'ROWGUIDCOL';
RULE:                                  'RULE';
SAVE:                                  'SAVE';
SCHEMA:                                'SCHEMA';
SECURITYAUDIT:                         'SECURITYAUDIT';
SELECT:                                'SELECT';
SEMANTICKEYPHRASETABLE:                'SEMANTICKEYPHRASETABLE';
SEMANTICSIMILARITYDETAILSTABLE:        'SEMANTICSIMILARITYDETAILSTABLE';
SEMANTICSIMILARITYTABLE:               'SEMANTICSIMILARITYTABLE';
SESSION_USER:                          'SESSION_USER';
SET:                                   'SET';
SETUSER:                               'SETUSER';
SHUTDOWN:                              'SHUTDOWN';
SOME:                                  'SOME';
STATISTICS:                            'STATISTICS';
SYSTEM_USER:                           'SYSTEM_USER';
TABLE:                                 'TABLE';
TABLESAMPLE:                           'TABLESAMPLE';
TEXTSIZE:                              'TEXTSIZE';
THEN:                                  'THEN';
TO:                                    'TO';
TOP:                                   'TOP';
TRAN:                                  'TRAN';
TRANSACTION:                           'TRANSACTION';
TRIGGER:                               'TRIGGER';
TRUNCATE:                              'TRUNCATE';
TSEQUAL:                               'TSEQUAL';
UNION:                                 'UNION';
UNIQUE:                                'UNIQUE';
UNPIVOT:                               'UNPIVOT';
UPDATE:                                'UPDATE';
UPDATETEXT:                            'UPDATETEXT';
USE:                                   'USE';
USER:                                  'USER';
VALUES:                                'VALUES';
VARYING:                               'VARYING';
VIEW:                                  'VIEW';
WAITFOR:                               'WAITFOR';
WHEN:                                  'WHEN';
WHERE:                                 'WHERE';
WHILE:                                 'WHILE';
WITH:                                  'WITH';
WITHIN:                                'WITHIN';
WRITETEXT:                             'WRITETEXT';
DOLLAR_PARTITION:                      '$PARTITION';

//Keywords that can exist in ID etc
ABSOLUTE:                              'ABSOLUTE';
AT_KEYWORD:                            'AT';
ACCENT_SENSITIVITY:                    'ACCENT_SENSITIVITY';
ACTION:                                'ACTION';
ACTIVATION:                            'ACTIVATION';
ACTIVE:                                'ACTIVE';
ADDRESS:                               'ADDRESS';
AES_128:                               'AES_128';
AES_192:                               'AES_192';
AES_256:                               'AES_256';
AFFINITY:                              'AFFINITY';
AFTER:                                 'AFTER';
AGGREGATE:                             'AGGREGATE';
ALGORITHM:                             'ALGORITHM';
ALLOW_ENCRYPTED_VALUE_MODIFICATIONS:   'ALLOW_ENCRYPTED_VALUE_MODIFICATIONS';
ALLOW_SNAPSHOT_ISOLATION:              'ALLOW_SNAPSHOT_ISOLATION';
ALLOWED:                               'ALLOWED';
ANSI_NULL_DEFAULT:                     'ANSI_NULL_DEFAULT';
ANSI_NULLS:                            'ANSI_NULLS';
ANSI_PADDING:                          'ANSI_PADDING';
ANSI_WARNINGS:                         'ANSI_WARNINGS';
APPLICATION_LOG:                       'APPLICATION_LOG';
APPLY:                                 'APPLY';
ARITHABORT:                            'ARITHABORT';
ASSEMBLY:                              'ASSEMBLY';
AUDIT:                                 'AUDIT';
AUDIT_GUID:                            'AUDIT_GUID';
AUTO:                                  'AUTO';
AUTO_CLEANUP:                          'AUTO_CLEANUP';
AUTO_CLOSE:                            'AUTO_CLOSE';
AUTO_CREATE_STATISTICS:                'AUTO_CREATE_STATISTICS';
AUTO_SHRINK:                           'AUTO_SHRINK';
AUTO_UPDATE_STATISTICS:                'AUTO_UPDATE_STATISTICS';
AUTO_UPDATE_STATISTICS_ASYNC:          'AUTO_UPDATE_STATISTICS_ASYNC';
AVAILABILITY:                          'AVAILABILITY';
AVG:                                   'AVG';
BACKUP_PRIORITY:                       'BACKUP_PRIORITY';
BEGIN_DIALOG:                          'BEGIN_DIALOG';
BIGINT:                                'BIGINT';
BINARY_KEYWORD:                        'BINARY';
BINARY_BASE64:                         'BINARY BASE64';
BINARY_CHECKSUM:                       'BINARY_CHECKSUM';
BINDING:                               'BINDING';
BLOB_STORAGE:                          'BLOB_STORAGE';
BROKER:                                'BROKER';
BROKER_INSTANCE:                       'BROKER_INSTANCE';
BULK_LOGGED:                           'BULK_LOGGED';
CALLER:                                'CALLER';
CAP_CPU_PERCENT:                       'CAP_CPU_PERCENT';
CAST:                                  'CAST';
TRY_CAST:                              'TRY_CAST';
CATALOG:                               'CATALOG';
CATCH:                                 'CATCH';
CHANGE_RETENTION:                      'CHANGE_RETENTION';
CHANGE_TRACKING:                       'CHANGE_TRACKING';
CHECKSUM:                              'CHECKSUM';
CHECKSUM_AGG:                          'CHECKSUM_AGG';
CLEANUP:                               'CLEANUP';
COLLECTION:                            'COLLECTION';
COLUMN_MASTER_KEY:                     'COLUMN_MASTER_KEY';
COMMITTED:                             'COMMITTED';
COMPATIBILITY_LEVEL:                   'COMPATIBILITY_LEVEL';
CONCAT:                                'CONCAT';
CONCAT_NULL_YIELDS_NULL:               'CONCAT_NULL_YIELDS_NULL';
CONTENT:                               'CONTENT';
CONTROL:                               'CONTROL';
COOKIE:                                'COOKIE';
COUNT:                                 'COUNT';
COUNT_BIG:                             'COUNT_BIG';
COUNTER:                               'COUNTER';
CPU:                                   'CPU';
CREATE_NEW:                            'CREATE_NEW';
CREATION_DISPOSITION:                  'CREATION_DISPOSITION';
CREDENTIAL:                            'CREDENTIAL';
CRYPTOGRAPHIC:                         'CRYPTOGRAPHIC';
CUME_DIST:                             'CUME_DIST';
CURSOR_CLOSE_ON_COMMIT:                'CURSOR_CLOSE_ON_COMMIT';
CURSOR_DEFAULT:                        'CURSOR_DEFAULT';
DATA:                                  'DATA';
DATE_CORRELATION_OPTIMIZATION:         'DATE_CORRELATION_OPTIMIZATION';
DATEADD:                               'DATEADD';
DATEDIFF:                              'DATEDIFF';
DATENAME:                              'DATENAME';
DATEPART:                              'DATEPART';
DAYS:                                  'DAYS';
DB_CHAINING:                           'DB_CHAINING';
DB_FAILOVER:                           'DB_FAILOVER';
DECRYPTION:                            'DECRYPTION';
DEFAULT_DOUBLE_QUOTE:                  ["]'DEFAULT'["];
DEFAULT_FULLTEXT_LANGUAGE:             'DEFAULT_FULLTEXT_LANGUAGE';
DEFAULT_LANGUAGE:                      'DEFAULT_LANGUAGE';
DELAY:                                 'DELAY';
DELAYED_DURABILITY:                    'DELAYED_DURABILITY';
DELETED:                               'DELETED';
DENSE_RANK:                            'DENSE_RANK';
DEPENDENTS:                            'DEPENDENTS';
DES:                                   'DES';
DESCRIPTION:                           'DESCRIPTION';
DESX:                                  'DESX';
DHCP:                                  'DHCP';
DIALOG:                                'DIALOG';
DIRECTORY_NAME:                        'DIRECTORY_NAME';
DISABLE:                               'DISABLE';
DISABLE_BROKER:                        'DISABLE_BROKER';
DISABLED:                              'DISABLED';
DISK_DRIVE:                            [A-Z][:];
DOCUMENT:                              'DOCUMENT';
DYNAMIC:                               'DYNAMIC';
ELEMENTS:                              'ELEMENTS';
EMERGENCY:                             'EMERGENCY';
EMPTY:                                 'EMPTY';
ENABLE:                                'ENABLE';
ENABLE_BROKER:                         'ENABLE_BROKER';
ENCRYPTED_VALUE:                       'ENCRYPTED_VALUE';
ENCRYPTION:                            'ENCRYPTION';
ENDPOINT_URL:                          'ENDPOINT_URL';
ERROR_BROKER_CONVERSATIONS:            'ERROR_BROKER_CONVERSATIONS';
EXCLUSIVE:                             'EXCLUSIVE';
EXECUTABLE:                            'EXECUTABLE';
EXIST:                                 'EXIST';
EXPAND:                                'EXPAND';
EXPIRY_DATE:                           'EXPIRY_DATE';
EXPLICIT:                              'EXPLICIT';
FAIL_OPERATION:                        'FAIL_OPERATION';
FAILOVER_MODE:                         'FAILOVER_MODE';
FAILURE:                               'FAILURE';
FAILURE_CONDITION_LEVEL:               'FAILURE_CONDITION_LEVEL';
FAST:                                  'FAST';
FAST_FORWARD:                          'FAST_FORWARD';
FILEGROUP:                             'FILEGROUP';
FILEGROWTH:                            'FILEGROWTH';
FILENAME:                              'FILENAME';
FILEPATH:                              'FILEPATH';
FILESTREAM:                            'FILESTREAM';
FILTER:                                'FILTER';
FIRST:                                 'FIRST';
FIRST_VALUE:                           'FIRST_VALUE';
FOLLOWING:                             'FOLLOWING';
FORCE:                                 'FORCE';
FORCE_FAILOVER_ALLOW_DATA_LOSS:        'FORCE_FAILOVER_ALLOW_DATA_LOSS';
FORCED:                                'FORCED';
FORMAT:                                'FORMAT';
FORWARD_ONLY:                          'FORWARD_ONLY';
FULLSCAN:                              'FULLSCAN';
FULLTEXT:                              'FULLTEXT';
GB:                                    'GB';
GETDATE:                               'GETDATE';
GETUTCDATE:                            'GETUTCDATE';
GLOBAL:                                'GLOBAL';
GO_BATCH:                              [\r\n]* [\t ]* 'GO'[\t\n\r ];
GO:                                    'GO';
GROUP_MAX_REQUESTS:                    'GROUP_MAX_REQUESTS';
GROUPING:                              'GROUPING';
GROUPING_ID:                           'GROUPING_ID';
HADR:                                  'HADR';
HASH:                                  'HASH';
HEALTH_CHECK_TIMEOUT:                  'HEALTH_CHECK_TIMEOUT';
HIGH:                                  'HIGH';
HONOR_BROKER_PRIORITY:                 'HONOR_BROKER_PRIORITY';
HOURS:                                 'HOURS';
IDENTITY_VALUE:                        'IDENTITY_VALUE';
IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX: 'IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX';
IMMEDIATE:                             'IMMEDIATE';
IMPERSONATE:                           'IMPERSONATE';
IMPORTANCE:                            'IMPORTANCE';
INCLUDE_NULL_VALUES:                   'INCLUDE_NULL_VALUES';
INCREMENTAL:                           'INCREMENTAL';
INITIATOR:                             'INITIATOR';
INPUT:                                 'INPUT';
INSENSITIVE:                           'INSENSITIVE';
INSERTED:                              'INSERTED';
INT:                                   'INT';
IP:                                    'IP';
ISOLATION:                             'ISOLATION';
JOB:                                   'JOB';
JSON:                                  'JSON';
KB:                                    'KB';
KEEP:                                  'KEEP';
KEEPFIXED:                             'KEEPFIXED';
KEY_SOURCE:                            'KEY_SOURCE';
KEYS:                                  'KEYS';
KEYSET:                                'KEYSET';
LAG:                                   'LAG';
LAST:                                  'LAST';
LAST_VALUE:                            'LAST_VALUE';
LEAD:                                  'LEAD';
LEVEL:                                 'LEVEL';
LIST:                                  'LIST';
LISTENER:                              'LISTENER';
LISTENER_URL:                          'LISTENER_URL';
LOB_COMPACTION:                        'LOB_COMPACTION';
LOCAL:                                 'LOCAL';
LOCATION:                              'LOCATION';
LOCK:                                  'LOCK';
LOCK_ESCALATION:                       'LOCK_ESCALATION';
LOGIN:                                 'LOGIN';
LOOP:                                  'LOOP';
LOW:                                   'LOW';
MANUAL:                                'MANUAL';
MARK:                                  'MARK';
MATERIALIZED:                          'MATERIALIZED';
MAX:                                   'MAX';
MAX_CPU_PERCENT:                       'MAX_CPU_PERCENT';
MAX_DOP:                               'MAX_DOP';
MAX_FILES:                             'MAX_FILES';
MAX_IOPS_PER_VOLUME:                   'MAX_IOPS_PER_VOLUME';
MAX_MEMORY_PERCENT:                    'MAX_MEMORY_PERCENT';
MAX_PROCESSES:                         'MAX_PROCESSES';
MAX_QUEUE_READERS:                     'MAX_QUEUE_READERS';
MAX_ROLLOVER_FILES:                    'MAX_ROLLOVER_FILES';
MAXDOP:                                'MAXDOP';
MAXRECURSION:                          'MAXRECURSION';
MAXSIZE:                               'MAXSIZE';
MB:                                    'MB';
MEDIUM:                                'MEDIUM';
MEMORY_OPTIMIZED_DATA:                 'MEMORY_OPTIMIZED_DATA';
MESSAGE:                               'MESSAGE';
MIN:                                   'MIN';
MIN_ACTIVE_ROWVERSION:                 'MIN_ACTIVE_ROWVERSION';
MIN_CPU_PERCENT:                       'MIN_CPU_PERCENT';
MIN_IOPS_PER_VOLUME:                   'MIN_IOPS_PER_VOLUME';
MIN_MEMORY_PERCENT:                    'MIN_MEMORY_PERCENT';
MINUTES:                               'MINUTES';
MIRROR_ADDRESS:                        'MIRROR_ADDRESS';
MIXED_PAGE_ALLOCATION:                 'MIXED_PAGE_ALLOCATION';
MODE:                                  'MODE';
MODIFY:                                'MODIFY';
MOVE:                                  'MOVE';
MULTI_USER:                            'MULTI_USER';
NAME:                                  'NAME';
NESTED_TRIGGERS:                       'NESTED_TRIGGERS';
NEW_ACCOUNT:                           'NEW_ACCOUNT';
NEW_BROKER:                            'NEW_BROKER';
NEW_PASSWORD:                          'NEW_PASSWORD';
NEXT:                                  'NEXT';
NO:                                    'NO';
NO_TRUNCATE:                           'NO_TRUNCATE';
NO_WAIT:                               'NO_WAIT';
NOCOUNT:                               'NOCOUNT';
NODES:                                 'NODES';
NOEXPAND:                              'NOEXPAND';
NON_TRANSACTED_ACCESS:                 'NON_TRANSACTED_ACCESS';
NORECOMPUTE:                           'NORECOMPUTE';
NORECOVERY:                            'NORECOVERY';
NOWAIT:                                'NOWAIT';
NTILE:                                 'NTILE';
NUMANODE:                              'NUMANODE';
NUMBER:                                'NUMBER';
NUMERIC_ROUNDABORT:                    'NUMERIC_ROUNDABORT';
OBJECT:                                'OBJECT';
OFFLINE:                               'OFFLINE';
OFFSET:                                'OFFSET';
OLD_ACCOUNT:                           'OLD_ACCOUNT';
ONLINE:                                'ONLINE';
ONLY:                                  'ONLY';
OPEN_EXISTING:                         'OPEN_EXISTING';
OPTIMISTIC:                            'OPTIMISTIC';
OPTIMIZE:                              'OPTIMIZE';
OUT:                                   'OUT';
OUTPUT:                                'OUTPUT';
OVERRIDE:                              'OVERRIDE';
OWNER:                                 'OWNER';
PAGE_VERIFY:                           'PAGE_VERIFY';
PARAMETERIZATION:                      'PARAMETERIZATION';
PARTITION:                             'PARTITION';
PARTITIONS:                            'PARTITIONS';
PARTNER:                               'PARTNER';
PATH:                                  'PATH';
PERCENT_RANK:                          'PERCENT_RANK';
PERCENTILE_CONT:                       'PERCENTILE_CONT';
PERCENTILE_DISC:                       'PERCENTILE_DISC';
POISON_MESSAGE_HANDLING:               'POISON_MESSAGE_HANDLING';
POOL:                                  'POOL';
PORT:                                  'PORT';
PRECEDING:                             'PRECEDING';
PRIMARY_ROLE:                          'PRIMARY_ROLE';
PRIOR:                                 'PRIOR';
PRIORITY:                              'PRIORITY';
PRIORITY_LEVEL:                        'PRIORITY_LEVEL';
PRIVATE:                               'PRIVATE';
PRIVATE_KEY:                           'PRIVATE_KEY';
PRIVILEGES:                            'PRIVILEGES';
PROCEDURE_NAME:                        'PROCEDURE_NAME';
PROPERTY:                              'PROPERTY';
PROVIDER:                              'PROVIDER';
PROVIDER_KEY_NAME:                     'PROVIDER_KEY_NAME';
QUERY:                                 'QUERY';
QUEUE:                                 'QUEUE';
QUEUE_DELAY:                           'QUEUE_DELAY';
QUOTED_IDENTIFIER:                     'QUOTED_IDENTIFIER';
RANGE:                                 'RANGE';
RANK:                                  'RANK';
RC2:                                   'RC2';
RC4:                                   'RC4';
RC4_128:                               'RC4_128';
READ_COMMITTED_SNAPSHOT:               'READ_COMMITTED_SNAPSHOT';
READ_ONLY:                             'READ_ONLY';
READ_ONLY_ROUTING_LIST:                'READ_ONLY_ROUTING_LIST';
READ_WRITE:                            'READ_WRITE';
READONLY:                              'READONLY';
REBUILD:                               'REBUILD';
RECEIVE:                               'RECEIVE';
RECOMPILE:                             'RECOMPILE';
RECOVERY:                              'RECOVERY';
RECURSIVE_TRIGGERS:                    'RECURSIVE_TRIGGERS';
RELATIVE:                              'RELATIVE';
REMOTE:                                'REMOTE';
REMOTE_SERVICE_NAME:                   'REMOTE_SERVICE_NAME';
REMOVE:                                'REMOVE';
REORGANIZE:                            'REORGANIZE';
REPEATABLE:                            'REPEATABLE';
REPLICA:                               'REPLICA';
REQUEST_MAX_CPU_TIME_SEC:              'REQUEST_MAX_CPU_TIME_SEC';
REQUEST_MAX_MEMORY_GRANT_PERCENT:      'REQUEST_MAX_MEMORY_GRANT_PERCENT';
REQUEST_MEMORY_GRANT_TIMEOUT_SEC:      'REQUEST_MEMORY_GRANT_TIMEOUT_SEC';
REQUIRED_SYNCHRONIZED_SECONDARIES_TO_COMMIT: 'REQUIRED_SYNCHRONIZED_SECONDARIES_TO_COMMIT';
RESERVE_DISK_SPACE:                    'RESERVE_DISK_SPACE';
RESOURCE:                              'RESOURCE';
RESOURCE_MANAGER_LOCATION:             'RESOURCE_MANAGER_LOCATION';
RESTRICTED_USER:                       'RESTRICTED_USER';
RETENTION:                             'RETENTION';
ROBUST:                                'ROBUST';
ROOT:                                  'ROOT';
ROUTE:                                 'ROUTE';
ROW:                                   'ROW';
ROW_NUMBER:                            'ROW_NUMBER';
ROWGUID:                               'ROWGUID';
ROWS:                                  'ROWS';
SAMPLE:                                'SAMPLE';
SCHEMABINDING:                         'SCHEMABINDING';
SCOPED:                                'SCOPED';
SCROLL:                                'SCROLL';
SCROLL_LOCKS:                          'SCROLL_LOCKS';
SEARCH:                                'SEARCH';
SECONDARY:                             'SECONDARY';
SECONDARY_ONLY:                        'SECONDARY_ONLY';
SECONDARY_ROLE:                        'SECONDARY_ROLE';
SECONDS:                               'SECONDS';
SECRET:                                'SECRET';
SECURITY:                              'SECURITY';
SECURITY_LOG:                          'SECURITY_LOG';
SEEDING_MODE:                          'SEEDING_MODE';
SELF:                                  'SELF';
SEMI_SENSITIVE:                        'SEMI_SENSITIVE';
SEND:                                  'SEND';
SENT:                                  'SENT';
SEQUENCE:                              'SEQUENCE';
SERIALIZABLE:                          'SERIALIZABLE';
SESSION_TIMEOUT:                       'SESSION_TIMEOUT';
SETERROR:                              'SETERROR';
SHARE:                                 'SHARE';
SHOWPLAN:                              'SHOWPLAN';
SIGNATURE:                             'SIGNATURE';
SIMPLE:                                'SIMPLE';
SINGLE_USER:                           'SINGLE_USER';
SIZE:                                  'SIZE';
SMALLINT:                              'SMALLINT';
SNAPSHOT:                              'SNAPSHOT';
SPATIAL_WINDOW_MAX_CELLS:              'SPATIAL_WINDOW_MAX_CELLS';
STANDBY:                               'STANDBY';
START_DATE:                            'START_DATE';
STATIC:                                'STATIC';
STATS_STREAM:                          'STATS_STREAM';
STATUS:                                'STATUS';
STATUSONLY:                            'STATUSONLY';
STDEV:                                 'STDEV';
STDEVP:                                'STDEVP';
STOPLIST:                              'STOPLIST';
STRING_AGG:                            'STRING_AGG';
STUFF:                                 'STUFF';
SUBJECT:                               'SUBJECT';
SUBSCRIPTION:                          'SUBSCRIPTION';
SUM:                                   'SUM';
SUSPEND:                               'SUSPEND';
SYMMETRIC:                             'SYMMETRIC';
SYNCHRONOUS_COMMIT:                    'SYNCHRONOUS_COMMIT';
SYNONYM:                               'SYNONYM';
SYSTEM:                                'SYSTEM';
TAKE:                                  'TAKE';
TARGET_RECOVERY_TIME:                  'TARGET_RECOVERY_TIME';
TB:                                    'TB';
TEXTIMAGE_ON:                          'TEXTIMAGE_ON';
THROW:                                 'THROW';
TIES:                                  'TIES';
TIME:                                  'TIME';
TIMEOUT:                               'TIMEOUT';
TIMER:                                 'TIMER';
TINYINT:                               'TINYINT';
TORN_PAGE_DETECTION:                   'TORN_PAGE_DETECTION';
TRANSFORM_NOISE_WORDS:                 'TRANSFORM_NOISE_WORDS';
TRIPLE_DES:                            'TRIPLE_DES';
TRIPLE_DES_3KEY:                       'TRIPLE_DES_3KEY';
TRUSTWORTHY:                           'TRUSTWORTHY';
TRY:                                   'TRY';
TSQL:                                  'TSQL';
TWO_DIGIT_YEAR_CUTOFF:                 'TWO_DIGIT_YEAR_CUTOFF';
TYPE:                                  'TYPE';
TYPE_WARNING:                          'TYPE_WARNING';
UNBOUNDED:                             'UNBOUNDED';
UNCOMMITTED:                           'UNCOMMITTED';
UNKNOWN:                               'UNKNOWN';
UNLIMITED:                             'UNLIMITED';
UOW:                                   'UOW';
USING:                                 'USING';
VALID_XML:                             'VALID_XML';
VALIDATION:                            'VALIDATION';
VALUE:                                 'VALUE';
VAR:                                   'VAR';
VARBINARY_KEYWORD:                     'VARBINARY';
VARP:                                  'VARP';
VIEW_METADATA:                         'VIEW_METADATA';
VIEWS:                                 'VIEWS';
WAIT:                                  'WAIT';
WELL_FORMED_XML:                       'WELL_FORMED_XML';
WITHOUT_ARRAY_WRAPPER:                 'WITHOUT_ARRAY_WRAPPER';
WORK:                                  'WORK';
WORKLOAD:                              'WORKLOAD';
XML:                                   'XML';
XMLDATA:                               'XMLDATA';
XMLNAMESPACES:                         'XMLNAMESPACES';
XMLSCHEMA:                             'XMLSCHEMA';
XSINIL:                                'XSINIL';
ZONE:                                  'ZONE';
DOLLAR_ACTION:                         '$ACTION';
//More keywords
ABSENT:                                'ABSENT';
AES:                                   'AES';
ALLOW_CONNECTIONS:                     'ALLOW_CONNECTIONS';
ALLOW_MULTIPLE_EVENT_LOSS:             'ALLOW_MULTIPLE_EVENT_LOSS';
ALLOW_SINGLE_EVENT_LOSS:               'ALLOW_SINGLE_EVENT_LOSS';
ANONYMOUS:                             'ANONYMOUS';
APPEND:                                'APPEND';
APPLICATION:                           'APPLICATION';
ASYMMETRIC:                            'ASYMMETRIC';
ASYNCHRONOUS_COMMIT:                   'ASYNCHRONOUS_COMMIT';
AUTHENTICATION:                        'AUTHENTICATION';
AUTOMATED_BACKUP_PREFERENCE:           'AUTOMATED_BACKUP_PREFERENCE';
AUTOMATIC:                             'AUTOMATIC';
AVAILABILITY_MODE:                     'AVAILABILITY_MODE';
BEFORE:                                'BEFORE';
BLOCK:                                 'BLOCK';
BLOCKSIZE:                             'BLOCKSIZE';
BLOCKING_HIERARCHY:                    'BLOCKING_HIERARCHY';
BUFFER:                                'BUFFER';
BUFFERCOUNT:                           'BUFFERCOUNT';
CACHE:                                 'CACHE';
CALLED:                                'CALLED';
CERTIFICATE:                           'CERTIFICATE';
CHANGETABLE:                           'CHANGETABLE';
CHANGES:                               'CHANGES';
CHECK_POLICY:                          'CHECK_POLICY';
CHECK_EXPIRATION:                      'CHECK_EXPIRATION';
CLASSIFIER_FUNCTION:                   'CLASSIFIER_FUNCTION';
CLUSTER:                               'CLUSTER';
COMPRESSION:                           'COMPRESSION';
CONFIGURATION:                         'CONFIGURATION';
CONTAINMENT:                           'CONTAINMENT';
CONTEXT:                               'CONTEXT';
CONTINUE_AFTER_ERROR:                  'CONTINUE_AFTER_ERROR';
CONTRACT:                              'CONTRACT';
CONTRACT_NAME:                         'CONTRACT_NAME';
CONVERSATION:                          'CONVERSATION';
COPY_ONLY:                             'COPY_ONLY';
CYCLE:                                 'CYCLE';
DATA_COMPRESSION:                      'DATA_COMPRESSION';
DATA_SOURCE:                           'DATA_SOURCE';
DATABASE_MIRRORING:                    'DATABASE_MIRRORING';
DEFAULT_DATABASE:                      'DEFAULT_DATABASE';
DEFAULT_SCHEMA:                        'DEFAULT_SCHEMA';
DIAGNOSTICS:                           'DIAGNOSTICS';
DIFFERENTIAL:                          'DIFFERENTIAL';
DTC_SUPPORT:                           'DTC_SUPPORT';
ENABLED:                               'ENABLED';
ENDPOINT:                              'ENDPOINT';
ERROR:                                 'ERROR';
EVENT:                                 'EVENT';
EVENTDATA:                             'EVENTDATA' '(' ')';
EVENT_RETENTION_MODE:                  'EVENT_RETENTION_MODE';
EXECUTABLE_FILE:                       'EXECUTABLE_FILE';
EXPIREDATE:                            'EXPIREDATE';
EXTENSION:                             'EXTENSION';
EXTERNAL_ACCESS:                       'EXTERNAL_ACCESS';
FAILOVER:                              'FAILOVER';
FAILURECONDITIONLEVEL:                 'FAILURECONDITIONLEVEL';
FAN_IN:                                'FAN_IN';
FILE_SNAPSHOT:                         'FILE_SNAPSHOT';
FORCESEEK:                             'FORCESEEK';
FORCE_SERVICE_ALLOW_DATA_LOSS:         'FORCE_SERVICE_ALLOW_DATA_LOSS';
GET:                                   'GET';
GOVERNOR:                              'GOVERNOR';
HASHED:                                'HASHED';
HEALTHCHECKTIMEOUT:                    'HEALTHCHECKTIMEOUT';
IIF:                                   'IIF';
IO:                                    'IO';
INCLUDE:                               'INCLUDE';
INCREMENT:                             'INCREMENT';
INFINITE:                              'INFINITE';
INIT:                                  'INIT';
INSTEAD:                               'INSTEAD';
ISNULL:                                'ISNULL';
KERBEROS:                              'KERBEROS';
KEY_PATH:                              'KEY_PATH';
KEY_STORE_PROVIDER_NAME:               'KEY_STORE_PROVIDER_NAME';
LANGUAGE:                              'LANGUAGE';
LIBRARY:                               'LIBRARY';
LIFETIME:                              'LIFETIME';
LINUX:                                 'LINUX';
LISTENER_IP:                           'LISTENER_IP';
LISTENER_PORT:                         'LISTENER_PORT';
LOCAL_SERVICE_NAME:                    'LOCAL_SERVICE_NAME';
LOG:                                   'LOG';
MATCHED:                               'MATCHED';
MASTER:                                'MASTER';
MAX_MEMORY:                            'MAX_MEMORY';
MAXTRANSFER:                           'MAXTRANSFER';
MAXVALUE:                              'MAXVALUE';
MAX_DISPATCH_LATENCY:                  'MAX_DISPATCH_LATENCY';
MAX_EVENT_SIZE:                        'MAX_EVENT_SIZE';
MAX_SIZE:                              'MAX_SIZE';
MAX_OUTSTANDING_IO_PER_VOLUME:         'MAX_OUTSTANDING_IO_PER_VOLUME';
MEDIADESCRIPTION:                      'MEDIADESCRIPTION';
MEDIANAME:                             'MEDIANAME';
MEMBER:                                'MEMBER';
MEMORY_PARTITION_MODE:                 'MEMORY_PARTITION_MODE';
MESSAGE_FORWARDING:                    'MESSAGE_FORWARDING';
MESSAGE_FORWARD_SIZE:                  'MESSAGE_FORWARD_SIZE';
MINVALUE:                              'MINVALUE';
MIRROR:                                'MIRROR';
MUST_CHANGE:                           'MUST_CHANGE';
NOFORMAT:                              'NOFORMAT';
NOINIT:                                'NOINIT';
NONE:                                  'NONE';
NOREWIND:                              'NOREWIND';
NOSKIP:                                'NOSKIP';
NOUNLOAD:                              'NOUNLOAD';
NO_CHECKSUM:                           'NO_CHECKSUM';
NO_COMPRESSION:                        'NO_COMPRESSION';
NO_EVENT_LOSS:                         'NO_EVENT_LOSS';
NOTIFICATION:                          'NOTIFICATION';
NTLM:                                  'NTLM';
OLD_PASSWORD:                          'OLD_PASSWORD';
ON_FAILURE:                            'ON_FAILURE';
PAGE:                                  'PAGE';
PARAM_NODE:                            'PARAM_NODE';
PARTIAL:                               'PARTIAL';
PASSWORD:                              'PASSWORD';
PERMISSION_SET:                        'PERMISSION_SET';
PER_CPU:                               'PER_CPU';
PER_DB:                                'PER_DB';
PER_NODE:                              'PER_NODE';
PERSISTED:                             'PERSISTED';
PLATFORM:                              'PLATFORM';
POLICY:                                'POLICY';
PREDICATE:                             'PREDICATE';
PROCESS:                               'PROCESS';
PROFILE:                               'PROFILE';
PYTHON:                                'PYTHON';
R:                                     'R';
READ_WRITE_FILEGROUPS:                 'READ_WRITE_FILEGROUPS';
REGENERATE:                            'REGENERATE';
RELATED_CONVERSATION:                  'RELATED_CONVERSATION';
RELATED_CONVERSATION_GROUP:            'RELATED_CONVERSATION_GROUP';
REQUIRED:                              'REQUIRED';
RESET:                                 'RESET';
RESTART:                               'RESTART';
RESUME:                                'RESUME';
RETAINDAYS:                            'RETAINDAYS';
RETURNS:                               'RETURNS';
REWIND:                                'REWIND';
ROLE:                                  'ROLE';
RSA_512:                               'RSA_512';
RSA_1024:                              'RSA_1024';
RSA_2048:                              'RSA_2048';
RSA_3072:                              'RSA_3072';
RSA_4096:                              'RSA_4096';
SAFETY:                                'SAFETY';
SAFE:                                  'SAFE';
SCHEDULER:                             'SCHEDULER';
SCHEME:                                'SCHEME';
SERVER:                                'SERVER';
SERVICE:                               'SERVICE';
SERVICE_BROKER:                        'SERVICE_BROKER';
SERVICE_NAME:                          'SERVICE_NAME';
SESSION:                               'SESSION';
SHRINKLOG:                             'SHRINKLOG';
SID:                                   'SID';
SKIP_KEYWORD:                          'SKIP';
SOFTNUMA:                              'SOFTNUMA';
SOURCE:                                'SOURCE';
SPECIFICATION:                         'SPECIFICATION';
SPLIT:                                 'SPLIT';
SQLDUMPERFLAGS:                        'SQLDUMPERFLAGS';
SQLDUMPERPATH:                         'SQLDUMPERPATH';
SQLDUMPERTIMEOUT:                      'SQLDUMPERTIMEOUTS';
STATE:                                 'STATE';
STATS:                                 'STATS';
START:                                 'START';
STARTED:                               'STARTED';
STARTUP_STATE:                         'STARTUP_STATE';
STOP:                                  'STOP';
STOPPED:                               'STOPPED';
STOP_ON_ERROR:                         'STOP_ON_ERROR';
SUPPORTED:                             'SUPPORTED';
TAPE:                                  'TAPE';
TARGET:                                'TARGET';
TCP:                                   'TCP';
TRACK_CAUSALITY:                       'TRACK_CAUSALITY';
TRANSFER:                              'TRANSFER';
UNCHECKED:                             'UNCHECKED';
UNLOCK:                                'UNLOCK';
UNSAFE:                                'UNSAFE';
URL:                                   'URL';
USED:                                  'USED';
VERBOSELOGGING:                        'VERBOSELOGGING';
VISIBILITY:                            'VISIBILITY';
WINDOWS:                               'WINDOWS';
WITHOUT:                               'WITHOUT';
WITNESS:                               'WITNESS';

//Build-ins:
VARCHAR:                               'VARCHAR';
NVARCHAR:                              'NVARCHAR';


SPACE:              [ \t\r\n]+    -> skip;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/slash-star-comment-transact-sql
COMMENT:            '/*' (COMMENT | .)*? '*/' -> channel(HIDDEN);
LINE_COMMENT:       '--' ~[\r\n]* -> channel(HIDDEN);

// TODO: ID can be not only Latin.
DOUBLE_QUOTE_ID:    '"' ~'"'+ '"';
SINGLE_QUOTE:       '\'';
SQUARE_BRACKET_ID:  '[' (~']' | ']' ']')* ']';
LOCAL_ID:           '@' ([A-Z_$@#0-9] | FullWidthLetter)*;
DECIMAL:             DEC_DIGIT+;
ID:                  ( [A-Z_#] | FullWidthLetter) ( [A-Z_#$@0-9] | FullWidthLetter )*;
STRING:              'N'? '\'' (~'\'' | '\'\'')* '\'';
BINARY:              '0' 'X' HEX_DIGIT*;
FLOAT:               DEC_DOT_DEC;
REAL:                (DECIMAL | DEC_DOT_DEC) ('E' [+-]? DEC_DIGIT+);

EQUAL:               '=';

GREATER:             '>';
LESS:                '<';
EXCLAMATION:         '!';

PLUS_ASSIGN:         '+=';
MINUS_ASSIGN:        '-=';
MULT_ASSIGN:         '*=';
DIV_ASSIGN:          '/=';
MOD_ASSIGN:          '%=';
AND_ASSIGN:          '&=';
XOR_ASSIGN:          '^=';
OR_ASSIGN:           '|=';

DOUBLE_BAR:          '||';
DOT:                 '.';
UNDERLINE:           '_';
AT:                  '@';
SHARP:               '#';
DOLLAR:              '$';
LR_BRACKET:          '(';
RR_BRACKET:          ')';
COMMA:               ',';
SEMI:                ';';
COLON:               ':';
STAR:                '*';
DIVIDE:              '/';
MODULE:              '%';
PLUS:                '+';
MINUS:               '-';
BIT_NOT:             '~';
BIT_OR:              '|';
BIT_AND:             '&';
BIT_XOR:             '^';

fragment LETTER:       [A-Z_];
fragment DEC_DOT_DEC:  (DEC_DIGIT+ '.' DEC_DIGIT+ |  DEC_DIGIT+ '.' | '.' DEC_DIGIT+);
fragment HEX_DIGIT:    [0-9A-F];
fragment DEC_DIGIT:    [0-9];


fragment FullWidthLetter
    : '\u00c0'..'\u00d6'
    | '\u00d8'..'\u00f6'
    | '\u00f8'..'\u00ff'
    | '\u0100'..'\u1fff'
    | '\u2c00'..'\u2fff'
    | '\u3040'..'\u318f'
    | '\u3300'..'\u337f'
    | '\u3400'..'\u3fff'
    | '\u4e00'..'\u9fff'
    | '\ua000'..'\ud7ff'
    | '\uf900'..'\ufaff'
    | '\uff00'..'\ufff0'
    // | '\u10000'..'\u1F9FF'  //not support four bytes chars
    // | '\u20000'..'\u2FA1F'
    ;